# -*- encoding: utf-8 -*-
import sys
import oss2
reload(sys)
sys.setdefaultencoding('utf8')
sys.path.append('C:\project\py_project\mudiao')

class Upload():

    def __init__(self, endpoint, accessKeyId, accessKeySecret, bucketName):

        self.endpoint = endpoint
        self.accessKeyId = accessKeyId
        self.accessKeySecret = accessKeySecret
        self.bucketName = bucketName
        self.auth = oss2.Auth(self.accessKeyId, self.accessKeySecret)
        self.bucket = oss2.Bucket(self.auth, "http://"+self.endpoint,self.bucketName)


    def upload(self, image_path, file_name):
        '''这里有可能超时异常，没遇到暂时不管'''
        self.bucket.put_object_from_file(file_name, image_path)
        image_path_url = "https://" + self.bucketName + "." + self.endpoint + "/" + file_name
        return image_path_url


if __name__=="__main__":
    upload = Upload()
